package kr.saeildamil.androidstudy_second.animation;

import kr.saeildamil.androidstudy_second.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;
import android.widget.ViewSwitcher.ViewFactory;

public class TextSwitcherTest extends Activity {
	TextSwitcher mSwitcher;
	int mAdIdx=0;
	String[] arAd = new String[]{
		"1.정력짱 ! 롯데 삼계탕",
		"2.MS 명품 마우스",
		"3.애플 아이 사과 쥬스",
		"4.신용불량자 긴급대출",
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch23_textswitchertest);
		
		mSwitcher = (TextSwitcher) findViewById(R.id.ch23_textswitcher_switcher);
		mSwitcher.setFactory(mFactory);
		
		mSwitcher.setText(arAd[mAdIdx]);
	}
	public void mOnClick(View v){
		switch(v.getId()){
			case R.id.ch23_textswitcher_btnnext:
				mAdIdx = mAdIdx == arAd.length -1 ?0:mAdIdx +1;
				mSwitcher.setText(arAd[mAdIdx]);
				break;
		}
	}
	ViewSwitcher.ViewFactory mFactory = new ViewSwitcher.ViewFactory() {
		
		@Override
		public View makeView() {
			TextView text = new TextView(TextSwitcherTest.this);
			text.setTextSize(22);
			text.setBackgroundColor(Color.YELLOW);
			text.setTextColor(Color.BLACK);
			return text;
		}
	};
}
